package com.caszx.chargingpile.fragment.station;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.util.TypedValue;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ScrollView;

import com.alibaba.fastjson.JSONException;
import com.alibaba.fastjson.util.TypeUtils;
import com.app.jsonparse.JSONParse;
import com.app.utils.DipPxUtil;
import com.app.view.HVScrollView;
import com.caszx.chargingpile.R;
import com.caszx.chargingpile.entity.EntityTabFeeScheme;
import com.caszx.chargingpile.entity.EntityTabStationDetail;
import com.caszx.chargingpile.widget.ExcelStationView;

import java.util.ArrayList;
import java.util.List;

import de.greenrobot.event.EventBus;


public class TabPlansFeeFragment extends Fragment {


    private ExcelStationView txtExcel;
    private HVScrollView mHVScrollView;
    private List<EntityTabFeeScheme> mListFeeScheme;
    public static TabPlansFeeFragment newInstance(String feeScheme) {
        TabPlansFeeFragment fragment = new TabPlansFeeFragment();
        Bundle bundle = new Bundle();
        bundle.putString("FEESCHEMA",feeScheme);
        fragment.setArguments(bundle);
        return fragment;
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        if (getArguments() != null) {
            String  stringFeeScheme = getArguments().getString("FEESCHEMA");
            if(stringFeeScheme!=null){
                try {
                    mListFeeScheme = JSONParse.parseArray(stringFeeScheme,EntityTabFeeScheme.class);
                }catch (JSONException e){

                }
            }
        }
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_plans_fee, container, false);
        initExcelView(view);
        mHVScrollView = (HVScrollView) view;
        mHVScrollView.setOnTouchListener(new View.OnTouchListener() {
            @Override
            public boolean onTouch(View v, MotionEvent event) {
                EventBus.getDefault().post(mHVScrollView.getScrollY() > 0?false:true);
                return false;
            }
        });

        return view;
    }

    private void initExcelView(View view){

        txtExcel = (ExcelStationView) view.findViewById(R.id.excel);
        txtExcel.setData(mListFeeScheme);

    }


}
